package oa.hleast.xswl.service.studies.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fasterxml.jackson.core.type.TypeReference;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import oa.hleast.common.utils.JsonUtil;
import oa.hleast.xswl.mapper.studies.ResearchActivitiesPathMapper;
import oa.hleast.xswl.pojo.domain.studies.ResearchActivitiesPath;
import oa.hleast.xswl.pojo.vo.studies.ResearchActivitesPathVo;
import oa.hleast.xswl.pojo.vo.studies.ResearchActivitesPointVo;
import oa.hleast.xswl.service.studies.service.ResearchActivitiesPathService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * 研学活动路线表(ResearchActivitiesPath)表服务实现类
 *
 * @author makejava
 * @since 2021-11-08 13:37:54
 */
@AllArgsConstructor
@Transactional
@Slf4j
@Service("researchActivitiesPathService")
public class ResearchActivitiesPathServiceImpl extends ServiceImpl<ResearchActivitiesPathMapper, ResearchActivitiesPath> implements ResearchActivitiesPathService {

    private final ResearchActivitiesPathMapper researchActivitiesPathDao;

    @Override
    public List<ResearchActivitesPathVo> findAll() {
        List<ResearchActivitesPathVo> researchActivitesPathVoList=new ArrayList<>();

        List<ResearchActivitiesPath> researchActivitiesPathList = researchActivitiesPathDao.selectList(new LambdaQueryWrapper<ResearchActivitiesPath>());
        researchActivitiesPathList.forEach(researchActivitiesPath -> {
            ResearchActivitesPathVo researchActivitesPathVo=new ResearchActivitesPathVo();

            Long id = researchActivitiesPath.getId();
            String researchActivitiesPathName = researchActivitiesPath.getResearchActivitiesPathName();
            String cmsPlaceInfoIdCollection = researchActivitiesPath.getCmsPlaceInfoIdCollection();
            ArrayList<ResearchActivitesPointVo> researchActivitesPointVoList = JsonUtil.string2Collection(cmsPlaceInfoIdCollection, new TypeReference<ArrayList<ResearchActivitesPointVo>>() {
            });
            researchActivitesPathVo.setId(id);
            researchActivitesPathVo.setResearchActivitiesPathName(researchActivitiesPathName);
            researchActivitesPathVo.setCmsPlaceInfoList(researchActivitesPointVoList);

            researchActivitesPathVoList.add(researchActivitesPathVo);
        });

        return researchActivitesPathVoList;
    }
}

